import ssl
# https://github.com/websocket-client/websocket-client
import websocket
from websocket import WebSocket
try:
    import thread
except ImportError:
    import _thread as thread
import time

def on_message(ws, message):
    print(message)
    # ws.close()

def on_error(ws, error):
    pass

def on_close(ws):
    print("### closed ###")

def on_open(ws):
    data = """
      {"type":"login","nameid":"9927873","token":"542056d868d54dc4a53f859f3187568a","userType":1}
      """
    ws.send(data)
    print("faseng")
    # thread.start_new_thread(run, ())



if __name__ == "__main__":
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("wss://so.z6002.com/bet",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    data = """
    {"type":"login","nameid":"9927873","token":"542056d868d54dc4a53f859f3187568a","userType":1}
    """
    # ws.send(data)
    ws.run_forever()

